package com.dawn.module.member.controller.admin.statistics;

import cn.hutool.core.util.ArrayUtil;
import com.dawn.framework.common.pojo.CommonResult;
import com.dawn.module.member.controller.admin.statistics.vo.*;
import com.dawn.module.member.service.infra.ApiAccessLogStatisticsService;
import com.dawn.module.member.service.statistics.MemberStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static com.dawn.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 会员统计")
@RestController
@RequestMapping("/member/statistics")
@Validated
@Slf4j
public class MemberStatisticsController {

    @Resource
    private MemberStatisticsService memberStatisticsService;
    @Resource
    private ApiAccessLogStatisticsService apiAccessLogStatisticsService;

    @GetMapping("/sex-statistics-list")
    @Operation(summary = "按照性别，获得会员统计列表")
    public CommonResult<List<MemberSexStatisticsRespVO>> getMemberSexStatisticsList() {
        return success(memberStatisticsService.getMemberSexStatisticsList());
    }

    @GetMapping("/terminal-statistics-list")
    @Operation(summary = "按照终端，获得会员统计列表")
    public CommonResult<List<MemberTerminalStatisticsRespVO>> getMemberTerminalStatisticsList() {
        return success(memberStatisticsService.getMemberTerminalStatisticsList());
    }

    // TODO @疯狂：要注意 date 的排序；
    @GetMapping("/user-count-comparison")
    @Operation(summary = "获得用户数量对照")
    public CommonResult<DataComparisonRespVO<MemberCountRespVO>> getUserCountComparison() {
        return success(memberStatisticsService.getUserCountComparison());
    }

    @GetMapping("/register-count-list")
    @Operation(summary = "获得会员注册数量列表")
    public CommonResult<List<MemberRegisterCountRespVO>> getMemberRegisterCountList(MemberAnalyseReqVO reqVO) {
        return success(memberStatisticsService.getMemberRegisterCountList(
                ArrayUtil.get(reqVO.getTimes(), 0), ArrayUtil.get(reqVO.getTimes(), 1)));
    }

}
